package com.lifa.controller;

import com.lifa.Utlis.StringUtil;
import com.lifa.dao.KucunDao;
import com.lifa.dao.RuKuDao;
import com.lifa.entity.RuKutable;
import com.lifa.entity.Rukumxtable;
import com.lifa.service.RuKuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/RuKuTongJi")
@Scope("prototype")
public class RuKuContorller {
    @Autowired
    private RuKuDao ruKuTongJiDao;

    @Autowired
    private RuKuService ruKuService;

    @Autowired
    private KucunDao kucunDao;

//    @RequestMapping("/queryRuKu")
//    @ResponseBody
//    public List<Kucun> queryRuKu(HttpServletRequest request){
//       List<Kucun>list=ruKuTongJiDao.getAllRuKu();
//       request.getSession().getServletContext().setAttribute("count",ruKuTongJiDao.getAllRuKuSL());
//       request.getSession().getServletContext().setAttribute("price",ruKuTongJiDao.getAllRuKuPrice());
//       return list;
//    }
//    public List<Kucun> queryRuKuSL(){
//        return ruKuTongJiDao.getAllRuKuSL();
//    }
//
//
//    public List<Kucun> queryRuKuPrice(){
//        return ruKuTongJiDao.getAllRuKuPrice();
//    }

    @RequestMapping("/queryByName")
    @ResponseBody
    public Map<String,Object> queryPageByName(String id, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("rows",ruKuTongJiDao.query(id,offset,limit));
        map.put("total",ruKuTongJiDao.getTotalCount(id));
        return map;
}




    @RequestMapping("/queryByNamechuku")
    @ResponseBody
    public Map<String,Object> queryPageByNamechuku(String id, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("rows",ruKuTongJiDao.querys(id,offset,limit));
        map.put("total",ruKuTongJiDao.getTotalCounts(id));
        return map;
    }


    @RequestMapping("/queryByrukumx")
    @ResponseBody
    public Map<String,Object> queryByrukumx(String id, int offset, int limit){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("rows",ruKuTongJiDao.querymx(id,limit,offset));
        map.put("total",ruKuTongJiDao.getTotalCountmx(id));
        return map;
    }





    @RequestMapping("/querydanhao")
    @ResponseBody
    public List<RuKutable> querydanhao(String danhao){
        return ruKuTongJiDao.listDanhao(danhao);
    }




    @RequestMapping("/querychukudanhao")
    @ResponseBody
    public List<RuKutable> querydanhaosss(String danhao){
        return ruKuTongJiDao.listchukudanhao(danhao);
    }




//    @RequestMapping("/queryByRuKuMX")
//    @ResponseBody
//    public Map<String,Object> queryRuKuMX(@RequestParam(value = "id" , defaultValue = "0") int id,int offset,int limit){
//        Map<String,Object> map=new HashMap<String,Object>();
//        map.put("rows",ruKuTongJiDao.queryRuKuMX(id,offset,limit));
//        map.put("total",ruKuTongJiDao.getTotalCountRuKuMX(id));
//        return map;
//    }
//
//
//
//    @RequestMapping("/mx")
//    @ResponseBody
//    public List<Kucun> querymx(){
//        List<Kucun> list=ruKuTongJiDao.getAllRuKujmx();
//        return list;
//    }


    //添加
    @RequestMapping("/rukutianjia")
    @ResponseBody
    public int rukutianjia(RuKutable ruKutable){
        return ruKuService.rukutianjia1(ruKutable);
    }

    /**
     * 随机生成单号
     * @return
     */
    @RequestMapping("/dhao")
    @ResponseBody
    public String dhao(){
        return StringUtil.shengChengDdid();
    }

    //出库添加
    @RequestMapping("/chukutianjia")
    @ResponseBody
    public int chukutianjia(RuKutable ruKutable){
        return ruKuTongJiDao.chukutianjia(ruKutable);
    }


    /**
     * 根据单号修改信息
     * @param ruKutable
     * @return
     */
    @RequestMapping("/xiugai")
    @ResponseBody
    public int xiugai(RuKutable ruKutable){
        return ruKuService.update(ruKutable);
    }

    /**
     * 获取到单号
     * @param rukudanhao
     * @return
     */
    @RequestMapping("/queryId")
    @ResponseBody
    public RuKutable queryId(String rukudanhao){
        return ruKuService.queryId(rukudanhao);
    }
    @RequestMapping("/selectruku")
    @ResponseBody
    public List<RuKutable> selectkucun(){
        return kucunDao.selectruke();
    }

    @RequestMapping("/bohui")
    @ResponseBody
    public int bohui(String rukudanhao){
        return ruKuTongJiDao.bohui(rukudanhao);
    }


}
